#include "msgUtils.h"
#include "../global/pathGlobal.h"

//获取mqid
int getMqId(){
     //获取key
    key_t key = ftok(MQPATH,PROID);
     if (key == -1)
    {
        perror("fotk(): ");
        return -1;
    }
    //创建或者获取队列返回消息队列id
    int mqId = msgget(key,IPC_CREAT|0666);
    if (mqId == -1)
    {
        perror("msgget(): ");
    }
    return mqId;
}

int sendMsg(int mqId,message* msg){
    int ret = msgsnd(mqId,msg,MSG_SIZE,0);  //0表示阻塞等待
     if (ret == -1)
    {
        perror("send msg error: ");
    }
    return ret;
}

int recvMsg(int mqId,message* msg){
    int ret = msgrcv(mqId,msg,MSG_SIZE,1,0);  //0,第一个类型，0表示阻塞等待
     if (ret == -1)
    {
        perror("recive msg error: ");
        return -1;
    }
    return ret;
}